import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProviderVO, ProviderForm, ProviderQuery } from '@/api/provider/provider/types';

/**
 * 查询上游供应商列表
 * @param query
 * @returns {*}
 */

export const listProvider = (query?: ProviderQuery): AxiosPromise<ProviderVO[]> => {
  return request({
    url: '/provider/provider/list',
    method: 'get',
    params: query
  });
};
/**
 * 查询所有上游供应商列表
 * @returns {*}
 */

export const listAllProvider = (): AxiosPromise<ProviderVO[]> => {
  return request({
    url: '/provider/provider/listAll',
    method: 'get'
  });
};

/**
 * 查询上游供应商详细
 * @param id
 */
export const getProvider = (id: string | number): AxiosPromise<ProviderVO> => {
  return request({
    url: '/provider/provider/' + id,
    method: 'get'
  });
};

/**
 * 新增上游供应商
 * @param data
 */
export const addProvider = (data: ProviderForm) => {
  return request({
    url: '/provider/provider',
    method: 'post',
    data: data
  });
};
/**
 * 新增上游供应商
 */
export const newProvider = () => {
  return request({
    url: '/provider/provider/new',
    method: 'get',
  });
};

/**
 * 修改上游供应商
 * @param data
 */
export const updateProvider = (data: ProviderForm) => {
  return request({
    url: '/provider/provider',
    method: 'put',
    data: data
  });
};

/**
 * 删除上游供应商
 * @param id
 */
export const delProvider = (id: string | number | Array<string | number>) => {
  return request({
    url: '/provider/provider/' + id,
    method: 'delete'
  });
};
